package com.example.texted.synchronizedlist;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Do {
    public static void main(String[] args) throws InterruptedException {
        List<String> synchronizedList = Collections.synchronizedList(new ArrayList<>());
        Runnable runnable1 = () -> {
            for (int i = 0; i < 2000; i++) {
                synchronizedList.add("1");
            }
        };
        Runnable runnable2 = () -> {
            for (int i = 0; i < 2000; i++) {
                synchronizedList.add("2");
            }
        };
        Runnable runnable3 = () -> {
            for (int i = 0; i < 2000; i++) {
                synchronizedList.add("3");
            }
        };
        new Thread(runnable1).start();
        new Thread(runnable2).start();
        new Thread(runnable3).start();
        Thread.sleep(1000);
        System.out.println(synchronizedList.size());
        System.out.println(synchronizedList);
    }
}
